<?php
/**
 * 责任链模式
 *把一个对象传递到一个对象链上，直到有对象处理这个对象
 * User: 16
 * Date: 2018/9/19
 * Time: 9:13
 */

error_reporting(-1);
ini_set('display_errors', 1);

spl_autoload_register("autoload");

function autoload($class)
{
    require dirname($_SERVER['SCRIPT_FILENAME']) . '//..//' . str_replace('\\', '/', $class) . '.php';
}

use chainOfResponsibility\HandlerAuthority;
use chainOfResponsibility\HandlerArguments;
use chainOfResponsibility\HandlerAccessToken;
use chainOfResponsibility\Request;

try{
    $request = new Request();
    $request->requestId = uniqid();

    //初始化验证器
    $authHandler = new HandlerAuthority();
    $argumentHandler = new HandlerArguments();
    $accessTokenHandler = new HandlerAccessToken();

    $accessTokenHandler->setNext($argumentHandler)->setNext($authHandler);
    $accessTokenHandler->start($request);
}catch (\Exception $e){
    echo "error:".$e->getMessage();
}